home *** CD-ROM | disk | FTP | other *** search
- Path: news.halcyon.com!usenet
- From: normanb@halcyon.com (Norm Bryar)
- Newsgroups: comp.lang.c++
- Subject: dynamic_cast costs?
- Date: Fri, 01 Mar 1996 16:45:17 GMT
- Organization: Northwest Nexus Inc.
- Message-ID: <4h79hl$7lc@news.halcyon.com>
- NNTP-Posting-Host: blv-pm10-ip9.halcyon.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- Has anyone profiled the cost of the dynamic_cast<> operation in C++?
- Colleaques tell me how expensive it is, but I a have a hard time
- believing it's any worst than, say, IUnknown->QueryInterface or other
- kind of switch-statement-based function-call. It's certainly not as
- expensive as an exception, is it?
- Doubtless for upcasts to base pointers, it's done at compile-time and
- so has no runtime expense, true?
- Also, what exactly happens if your base classes are in one DLL
- compiled with RTTI enabled (/GR on MSVC4.0), but some derived classes
- are in another DLL w/o RTTI. If I pass a pDerived into a function as
- a pBase pointer, can I downcast to any base class that compiled with
- RTTI or am I completely hosed?
- Lastly, in MSVC4, I erroneously tried getting from B1 to B2 without an
- intermediate dynamic_cast to D in the following hierarchy:
-
- class D : public B1, public B2.
-
- It threw an access violation and then a "MS C++ Exception." I thought
- it was just supposed to return NULL if it couldn't make the cast.
- Thoughts?
-
- --Norm
-
-